package com.letfox.auth.controller.auth;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.letfox.auth.controller.BaseController;
import com.letfox.auth.model.RegisterModel;
import com.letfox.auth.service.LoginService;
import com.letfox.common.enums.ResponseEnum;
import com.letfox.common.model.ResultResponse;
import com.letfox.common.util.MD5Util;
import com.letfox.user.model.UAccount;

@Controller
@RequestMapping(value = "/login")
public class Login_Controller extends BaseController{
	@Autowired
	private LoginService loginService;
	
	@RequestMapping(value = "/save",method=RequestMethod.POST)
	@ResponseBody
	public ResultResponse createAcount(@RequestParam String account, @RequestParam String password) {
		try{
			UAccount uAccount=new UAccount();
			uAccount.setAccount(account);
			uAccount.setPassword(MD5Util.MD5(password));
			//注册
			resultResponse = loginService.createAccount(uAccount);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			resultResponse.setStatusCode(ResponseEnum.R500.getCode());
			resultResponse.setStatusMessage(ResponseEnum.R500.getMessage());
		}
		return resultResponse;
	}
	
	@RequestMapping(value = "/getAcc",method=RequestMethod.POST)
	@ResponseBody
	public ResultResponse getAcount(@RequestParam String account, @RequestParam String password) {
		try{
			//登陆
			resultResponse = loginService.getLogin(account, password);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			resultResponse.setStatusCode(ResponseEnum.R500.getCode());
			resultResponse.setStatusMessage(ResponseEnum.R500.getMessage());
		}
		return resultResponse;
	}
}
